/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: jse2302 - Ex2
 * <p>Powered by webrx On 2023-06-19 16:22:47
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入字符串:");
        String str = sc.next();
        System.out.printf("正常：%s%n", str);

        //方式一
        String t = "";
        for (int i = 0; i < str.length(); i++) {
            t = str.substring(i, i + 1) + t;
        }
        System.out.printf("逆序：%s%n", t);

        //方式二
        StringBuilder s2 = new StringBuilder(t);
        System.out.printf("逆序：%s%n", s2.reverse());

        //乱
        char[] cs = t.toCharArray();
        Random rand = new Random();
        for (int i = 0; i < cs.length * 10; i++) {
            int x = rand.nextInt(cs.length);
            int y = rand.nextInt(cs.length);
            if (x == y) {
                i--;
                continue;
            }
            char tt = cs[x];
            cs[x] = cs[y];
            cs[y] = tt;
        }
        System.out.println(new String(cs));


    }
}
